package com.haidechizi.i18n.code.generator.common.message.key;


import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.haidechizi.i18n.code.generator.common.message.utils.KeyUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 默认的key generator
 * 按照下划线
 */
@Slf4j
public class DefaultKeyGenerator extends BaseKeyGenerator {

    /**
     *
     * @param name
     * @param fileType
     * @param content
     * @return
     */
    @Override
    public String generatorKey(String name, String fileType, String content) {
        try {
            return PinyinHelper.convertToPinyinString(name, "_", PinyinFormat.WITHOUT_TONE);
        } catch (PinyinException e) {
            log.warn("生成key失败,name:{}", name, e);
        }
        return KeyUtils.generatorKey();

    }

    /**
     * key generator 名称
     *
     * @return
     */
    @Override
    public String name() {
        return "default";
    }
}
